﻿using Erp.BO;
using Ice.Core;
using Ice.Lib.Framework;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SupplyChainWinE10
{
    public partial class Form1 :Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void epiButtonC1_Click(object sender, System.EventArgs args)
        {
            //DataTable dt = new DataTable();
            //try
            //{
            //    OpenFileDialog ofd = new OpenFileDialog();
            //    ofd.Filter = "Excel 文件|*.xls;*.xlsx";
            //    if (ofd.ShowDialog() == DialogResult.OK)
            //    {
            //        string filePath = ofd.FileName;

            //        string strConn;
            //        strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties='Excel 8.0;HDR=False;IMEX=1'";
            //        OleDbConnection OleConn = new OleDbConnection(strConn);
            //        OleConn.Open();
            //        string sql = "SELECT * FROM  [Sheet1$]  ";
            //        OleDbDataAdapter OleDaExcel = new OleDbDataAdapter(sql, OleConn);
            //        DataSet OleDsExcle = new DataSet();
            //        OleDaExcel.Fill(OleDsExcle, "Sheet1");
            //        OleConn.Close();
            //        MessageBox.Show("载入数据条数" + OleDsExcle.Tables[0].Rows.Count);
            //        if (OleDsExcle.Tables[0].Rows.Count == 0)
            //        {
            //            MessageBox.Show("载入Excel失败!失败原因：选择的Excel中没有数据", "错误提示");
            //        }
            //        else
            //        {
            //            dt = OleDsExcle.Tables[0];
            //            bool success = false;
            //            string EpiUserID = "manager";
            //            string EpiPassWord = "manager";
            //            string EpiAppUrl = System.Configuration.ConfigurationManager.AppSettings["EpiAppUrl"];
            //            string EpiAppConfig = System.Configuration.ConfigurationManager.AppSettings["EpiAppConfig"];
            //            string epiconfigpath = AppDomain.CurrentDomain.BaseDirectory + EpiAppConfig;
            //            using (Session e10session = new Session(EpiUserID, EpiPassWord, EpiAppUrl, Session.LicenseType.DataCollection, epiconfigpath))
            //            using (var partBO = WCFServiceSupport.CreateImpl<Erp.Proxy.BO.PartImpl>(e10session, Erp.Proxy.BO.PartImpl.UriPath))
            //            {
            //                PartDataSet partDS;
            //                foreach (DataRow row in dt.Rows)
            //                {
            //                    partDS = new Erp.BO.PartDataSet();
            //                    //newPart(row, partDS, partBO);

            //                }


            //            }

            //        }
            //    }
            //    else
            //        return;
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show("数据绑定Excel失败!失败原因：" + ex.Message, "错误提示");
            //}
            //if (dt.Rows.Count > 0)
            //    MessageBox.Show(dt.Rows.Count.ToString());
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string EpiUserID = "tt";
            string EpiPassWord = "123456";
            string EpiAppUrl = System.Configuration.ConfigurationManager.AppSettings["EpiAppUrl"];
            string EpiAppConfig = System.Configuration.ConfigurationManager.AppSettings["EpiAppConfig"];
            string epiconfigpath = AppDomain.CurrentDomain.BaseDirectory + EpiAppConfig;
            // string epiconfigpath = @"C:\Epicor\ERP10\LocalClients\ERP102200\config\" + EpiAppConfig;
            using (Session e10session = new Session(EpiUserID, EpiPassWord, EpiAppUrl, Session.LicenseType.DataCollection, epiconfigpath))
            using (var orderdtlBO = WCFServiceSupport.CreateImpl<Erp.Proxy.BO.OrderDtlSearchImpl>(e10session, Erp.Proxy.BO.OrderDtlSearchImpl.UriPath))
            {
                bool exist = false;
                string whereClause = string.Format("OrderComment like '%{0}%'", "5688606");//OpenLAine =1
                bool morePages;
                OrderDtlSearchDataSet dtls = orderdtlBO.GetRows(whereClause, 0, 0, out morePages);
                if (dtls != null && dtls.Tables.Count > 0 && dtls.Tables[0].Rows.Count > 0)
                {
                    exist = true;
                }


            }
        }

        //private void newPart(DataRow row, PartDataSet partDS, Erp.Proxy.BO.PartImpl partBO)
        //{

        //    partBO.GetNewPart(partDS);
        //    //partDS.Tables["Part"].Rows[0] = row["PartNum"].ToString();
        //    partBO.ChangePartNum("", partDS);

        //    string cPartChangedMsgText = "";
        //    string cPartSNChangedMsgText = "";
        //    partBO.CheckPartChanges(partDS, out cPartChangedMsgText, out cPartSNChangedMsgText);

        //    partBO.Update(partDS);
        //}
    }
}
